import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Address } from "src/entity/address.entity";
import { Repository } from "typeorm";

@Injectable()
export class AddressService {
  constructor(
    @InjectRepository(Address)
    private addressRepository: Repository<Address>,
  ) {}

  async findAll(): Promise<Address[]> {
    return this.addressRepository.find();
  }

  async findOne(id: number): Promise<Address> {
    return this.addressRepository.findOneBy({ id });
  }
  
  async addOne(address: Address) {
    return this.addressRepository.insert(address)
  }

  async updateOne(address: Address) {
    return this.addressRepository.save(address)
  }

  async remove(id: number) {
    return this.addressRepository.delete(id);
  }
}